package com.stroke.core;

import org.apache.log4j.Logger;

/**
 * Author: Igor Bubelov
 * Date: 3/5/11 7:54 PM
 */
public class Updater extends CoreRunnable {
    public Updater(int ups) {
        super(ups);
    }

    public void run() {
        while (true) {
            if (paused) {
                sleep(10);
                continue;
            }

            long time = System.currentTimeMillis();

            Logger.getLogger(Updater.class).trace("Updating...");
            EntityManager.getInstance().update();
            Logger.getLogger(Updater.class).trace("Updated");

            time = System.currentTimeMillis() - time;

            sleep(time > period ? 0 : (long) period - time);
        }
    }
}